package com.ymttest.database.sqlwapper;

import java.util.Date;
import java.util.List;

import com.ymt.core.tool.Logger;
import com.ymt.database.SqlManager;
import com.ymttest.database.model.YmtIdCard;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;

/************************************************************************************
 * @File name : YmtUserWapper.java
 * @Author : zhouyi
 * @Date : 2015年4月2日
 * @Copyright : 洋码头
 ************************************************************************************/
public class YmtIdCardWapper {
	SqlManager manage;

	public YmtIdCardWapper() {
		manage = new SqlManager("ymt" + EnvSetup.getEnv());
	}

	/**
	 * 获取userid 查询idcard 信息
	 * 
	 * @param userid
	 * @return YmtProducts
	 * @throws InterruptedException
	 */
	public List<YmtIdCard> selectIdCardByUserId(String userid) throws InterruptedException {
		List<YmtIdCard> idCardList = manage.getSelectResults(
				"com.ymttest.database.mapping.YmtIdCardMapper.selectByiUserId", userid);

		// manage.close();
		return idCardList;
	}

	/**
	 * insert 一条YmtIdCard记录
	 * 
	 * @param record
	 *            insertProducts
	 * @return
	 * @throws InterruptedException
	 */
	public int insertIdCardUserId(YmtIdCard record) {
		int i = manage.insert("com.ymttest.database.mapping.YmtIdCardMapper.insert", record);
		manage.commit();
		// manage.close();
		return i;
	}

	/**
	 * 根据userid 删除idcard 数据
	 * 
	 * @param userid
	 * @return
	 * @throws InterruptedException
	 */
	public int deleterIdCardByUserId(String userid) {
		int i = manage.insert("com.ymttest.database.mapping.YmtIdCardMapper.deleterByiUserId", userid);
		manage.commit();
		return i;
	}

	/**
	 * 关闭数据库连接
	 */
	public void close() {
		manage.close();
	}

	@Override
	protected void finalize() throws Throwable {
		this.close();
		manage = null;
		super.finalize();
	}

	public static void main(String args[]) {
		try {

			YmtIdCard id = new YmtIdCard();
			id.setSid(TestDataManager.getRandomUUID().toString());
			id.setIuserid(20000342);
			id.setSname("test");
			id.setIaction(1);
			id.setScardid("0000000000000");
			id.setSphone("1231");
			id.setDaddtime(new Date());
			Logger.debug(new YmtIdCardWapper().selectIdCardByUserId("20000342").size());
			// Logger.debug(new YmtIdCardWapper().insertIdCardUserId(id));
			Logger.debug(new YmtIdCardWapper().deleterIdCardByUserId("20000342"));
		} catch (InterruptedException e) {

			e.printStackTrace();
		}

	}
}
